fix: standardize tool function docstrings to Google Python style#47
Closed
Ridwannurudeen wants to merge 1 commit intoNousResearch:mainfrom
Closed
fix: standardize tool function docstrings to Google Python style#47Ridwannurudeen wants to merge 1 commit intoNousResearch:mainfrom
Ridwannurudeen wants to merge 1 commit intoNousResearch:mainfrom
Conversation
Closes NousResearch#14 LangChain's `_parse_python_function_docstring` expects docstrings to follow the Google Python style guide in order to correctly extract function descriptions and parameter metadata for OpenAI tool schemas. The existing docstrings in `functions.py` had several formatting issues that caused `convert_to_openai_tool` to produce malformed tool definitions: 1. Missing 4-space indentation under Args/Returns sections (get_financial_statements, get_key_financial_ratios, get_analyst_recommendations, get_dividend_data, get_company_news, get_technical_indicators, get_company_profile) 2. Inconsistent 2-space indentation instead of 4-space (get_current_stock_price) 3. Note section leaking into tool description (code_interpreter) 4. Detailed Keys block under Returns parsed as description text (get_stock_fundamentals) 5. Missing blank line between Args and Returns sections (google_search_and_scrape) 6. Return type mismatch between docstring (list) and type hint (dict) (google_search_and_scrape) All 11 @tool-decorated functions now follow a consistent format: - Summary on the opening line (no blank line after triple quotes) - 4-space indented Args section with (type) annotations - 4-space indented Returns section - Blank line separating each section - No extraneous sections (Note, Keys) that confuse the parser
Author
|
Friendly ping — this fixes #14 by standardizing all 11 tool docstrings to Google Python style so convert_to_openai_tool() generates correct schemas. No functional code changes, just docstring formatting. Happy to adjust if needed. |
Author
|
Closing as superseded by #49. |
Author
|
Superseded by #49, which contains runtime correctness fixes plus regression tests. Closing this PR to focus review on the higher-impact changes. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #14
Rewrites all 11
@tool-decorated function docstrings infunctions.pyto follow the Google Python Style Guide, which LangChain's_parse_python_function_docstringrequires to correctly generate OpenAI tool schemas viaconvert_to_openai_tool().Problem
With the old formatting,
convert_to_openai_tool()failed to separate the function description from its parameter metadata. The result was tool schemas where:descriptionfield contained the entire docstring (including rawArgs:,Returns:,Note:, andKeys:sections)parameters.propertiesentries had nodescriptionfieldWhat changed
Every docstring in
functions.pynow follows this structure:Specific fixes per function:
code_interpreterNote:section that leaked into description; moved context intoArgs:google_search_and_scrapeArgs:andReturns:; fixed return typelist→dictto match type hintget_current_stock_priceget_stock_fundamentalsKeys:block into a singleReturns:lineget_financial_statementsget_key_financial_ratiosget_analyst_recommendationsget_dividend_dataget_company_newsget_technical_indicatorsget_company_profileScope
get_openai_tools()are coveredTest plan
convert_to_openai_tool()receives properly formatted input